Public Class MainForm

    Private Sub AddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToolStripMenuItem.Click
        Static i As Integer = 0
        Static count As Integer = 0
        Dim f As Form
        f = New Form
        f.Text = "Tab " & i
        TabControl4.TabPages.Add(f)
        f = New Form
        f.Text = "Tab " & i
    End Sub

    Sub TabMouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Right Then
            Dim x As New ContextMenuStrip
            Dim t As ToolStripItem = x.Items.Add("Close it", Nothing, AddressOf Closeit)
            t.Tag = sender
            x.Show(sender, e.Location)
        End If
    End Sub

    Sub Closeit(ByVal sender As Object, ByVal e As EventArgs)
        sender.tag.Form.close()
    End Sub

    Private Sub RemoveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveToolStripMenuItem.Click
        If TabControl4.TabPages.Count > 0 Then TabControl4.TabPages.Remove(TabControl4.TabPages.SelectedTab)
    End Sub

    Private Sub TabControl1_GetTabRegion(ByVal sender As Object, ByVal e As MdiTabControl.TabControl.GetTabRegionEventArgs)
        Array.Resize(e.Points, 4)
        If e.Selected Then
            e.Points(0) = New Point(0, e.TabHeight)
            e.Points(1) = New Point(0, 0)
            e.Points(2) = New Point(e.TabWidth, 0)
            e.Points(3) = New Point(e.TabWidth, e.TabHeight)
        Else
            e.Points(0) = New Point(0, e.TabHeight - 2)
            e.Points(1) = New Point(0, -1)
            e.Points(2) = New Point(e.TabWidth, -1)
            e.Points(3) = New Point(e.TabWidth, e.TabHeight - 2)
        End If
    End Sub

    Private Sub TabControl2_GetTabRegion(ByVal sender As Object, ByVal e As MdiTabControl.TabControl.GetTabRegionEventArgs)
        e.Points(1) = New Point(e.TabHeight - 2, 2)
        e.Points(2) = New Point(e.TabHeight + 2, 0)
    End Sub

    Private Sub TabControl5_GetTabRegion(ByVal sender As Object, ByVal e As MdiTabControl.TabControl.GetTabRegionEventArgs)
        Array.Resize(e.Points, 8)
        e.Points(0) = New Point(0, 19)
        e.Points(1) = New Point(7, 5)
        e.Points(2) = New Point(10, 2)
        e.Points(3) = New Point(13, 0)
        e.Points(4) = New Point(e.TabWidth - 13, 0)
        e.Points(5) = New Point(e.TabWidth - 10, 2)
        e.Points(6) = New Point(e.TabWidth - 7, 5)
        e.Points(7) = New Point(e.TabWidth, 19)
    End Sub

    Private Sub TabControl7_GetTabRegion(ByVal sender As Object, ByVal e As MdiTabControl.TabControl.GetTabRegionEventArgs)
        Dim x As New Drawing2D.GraphicsPath
        x.AddArc(New Rectangle(0, 0, e.TabWidth, e.TabHeight * 2 / 3), 0, -180)
        x.Flatten()
        Array.Resize(e.Points, x.PointCount)
        For i As Integer = 0 To x.PointCount - 1
            e.Points(i) = New Point(x.PathPoints(i).X, x.PathPoints(i).Y)
        Next
    End Sub

    Private Sub TabControl3_TabPaintBorder(ByVal sender As Object, ByVal e As MdiTabControl.TabControl.TabPaintEventArgs)
        If Not e.Selected Then
            e.Handled = True
            e.Graphics.DrawLine(Pens.Azure, e.ClipRectangle.Width - 1, 2, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 3)
        End If
    End Sub

    Private Sub TabControl6_TabPaintBorder(ByVal sender As Object, ByVal e As MdiTabControl.TabControl.TabPaintEventArgs)
        If e.Selected Or e.Hot Then
            e.Handled = False
            e.Graphics.FillRectangle(Brushes.Orange, 0, 0, e.TabWidth, 3)
        End If
    End Sub

    Private Sub ChangePropertiesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangePropertiesToolStripMenuItem.Click
        TabControl4.CloseButtonVisible = True
        'TabControl4.TabCloseButtonImage = 
        'TabControl4.TabCloseButtonImageDisabled = TabControl1.TabCloseButtonImageDisabled
        'TabControl4.TabCloseButtonImageHot = TabControl1.TabCloseButtonImageHot
        TabControl4.TabCloseButtonSize = New Size(10, 10)
        TabControl4.TabHeight = 12
        TabControl4.TabIconSize = New Size(10, 10)
        TabControl4.TabOffset = 10
    End Sub

    Private Icons(7) As Icon

    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'ToolStripManager.VisualStylesEnabled = False
        For i As Integer = 0 To 7
            Dim b As Bitmap = ImageList1.Images(i)
            Icons(i) = Drawing.Icon.FromHandle(b.GetHicon)
            b.Dispose()
            b = Nothing
        Next
        'TabControl7.SetColors(New ProfessionalColorTable)
    End Sub

    Private Sub AnimateIconToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnimateIconToolStripMenuItem.Click
        If AnimateIconToolStripMenuItem.Checked Then
            Timer1.Stop()
            AnimateIconToolStripMenuItem.Checked = False
            AnimateIconToolStripMenuItem.Text = "Animate Icon"
        Else
            Timer1.Start()
            AnimateIconToolStripMenuItem.Checked = True
            AnimateIconToolStripMenuItem.Text = "Stop Animation"
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static Loading As Boolean = False
        Try
            If Loading Then Exit Sub
            Loading = True
            Static i As Integer = 0
            For Each t As MdiTabControl.TabPage In TabControl4.TabPages
                t.Icon = Icons(i)
            Next
            i = i + 1
            If i >= 8 Then i = 0
        Catch ex As Exception
        Finally
            Loading = False
        End Try
    End Sub

    Private Sub UntabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UntabToolStripMenuItem.Click
        TabControl4.TabPages.TearOff(TabControl4.TabPages.SelectedTab)
        

        'Dim f As Form = TabControl4.TabPages.SelectedTab.Form
        'f.Parent.Controls.Remove(f)
        'f.TopLevel = True
        'f.Dock = DockStyle.None
        'f.Top = 10
        'f.Left = 10
        'f.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        'f.ShowInTaskbar = True
        'f.Show()
        'Dim T As MdiTabControl.TabPage = TabControl4.TabPages.SelectedTab
        'T.Dispose()
        'TabControl4.TabPages.Remove(TabControl4.TabPages.SelectedTab)
    End Sub

    Private Sub TabControl4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl4.Load

    End Sub
End Class